<template>
	<view>
		客户信息：{{model.c_id}}-{{model.c_name}}-{{msg}}
		<uni-list>
			<uni-list-item  :title="'编号：' + model.c_id"></uni-list-item>
			<uni-list-item  :title="model.c_name"></uni-list-item>
			<uni-list-item  :title="model.c_sex?'男':'女'"></uni-list-item>
			<uni-list-item  :title="model.c_phone"></uni-list-item>
			<uni-list-item  :title="model.c_address"></uni-list-item>
			<uni-list-item  :title="model.c_age"></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {c_id:'',
				c_name:'',
				c_sex:'',
				c_phone:'',
				c_address:'',
				c_age:''},
				msg: ''
			}
		},
		onLoad(options) {
			// console.log(options);
			// if (options.c_id) {
			// 	this.customerid = options.c_id
			// }
			const eventChannel = this.getOpenerEventChannel()
			// 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
			eventChannel.on('send',(data)=> {
				console.log(data);
				this.model.AutoID = data.AutoID
				// this.model = data
				if (this.model.AutoID) {
					this.fetch(this.model.AutoID)
				}
					});
			// uni.$on() 在里面要使用临时变量var _this = this;
			let _this = this
			  uni.$on('update',(data)=>{
			        console.log('监听到事件来自 update ，携带参数 msg 为：' + data.msg);
					
					this.msg =  data.msg;
					
					
			    })
			
		},
		onUnload() {
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.off('send');
			uni.$off('send')
		},
		methods: {
			fetch(id) {
			  uni.request({
			  	url: `${this.apiUrl}/rest/ad/${id}`,
			  	method: 'GET',
			  	data: {},
			  	success: (res) => {
					 this.model = Object.assign({}, this.model, res.data);
			  		console.log(this.items)
			  	},
			  	fail: () => {
			  
			  	},
			  	complete: () => {
			  
			  	}
			  })
			},
		}
	}
</script>

<style>

</style>
